const cookie = {
  setItem(key, value, ops={}){
    let expires = "";
    if( ops.expires ){
      const d = new Date();
      d.setDate( d.getDate() + ops.expires );
      expires = `;expires=${d}`;
    }
    let path = ops.path ? `;path=${ops.path}` : "";
    document.cookie = `${key}=${value}${expires}${path}`;
  },
  removeItem(key, ops={}){
    ops.expires = -1;
    this.setItem(key, "", ops);
  },
  getItem(key){
    let arr = document.cookie.split("; ")
    for(let i=0;i<arr.length;i++){
      const val = arr[i].split("=");
      if(val[0] === key){
        return val[1];
      }
    }
    return null;
  }
}

